# /usr/bin/python
# encoding:utf-8
from pylab import *
import os


class GetRes(object):
        def __init__(self, *args, **kargs):
            adb_info_cmd = {
                "phone_device": "adb get-serialno",
                "phone_version": "adb shell getprop ro.build.version.release",
                "sdk_version": "adb shell getprop ro.build.version.sdk",
                "phone_model": "adb -d shell getprop ro.product.model",
                "phone_brand": "adb -d shell getprop ro.product.brand",
            }
            self.cmd = adb_info_cmd

        def phone_info(self):
            cmd = self.cmd
            for k in cmd:
                # print("%s =" % k, adb_cmd[k])
                respone_info = os.popen(cmd[k]).readline().strip('\n')
                cmd[k] = respone_info
            print(cmd)
            return cmd

        def get_cpu(self, find_types, package_name):
            try:
                cpu_str = os.popen(("adb shell dumpsys cpuinfo | %s  %s") % (find_types, package_name))
                cpu_list = cpu_str.readline().split()
                # print(cpu_list)
                if len(cpu_list) > 0:
                    cpu = cpu_list[0].replace("%", "")
                else:
                    cpu = "0"
                # print(cpu)
            except e:
                print("error: "+e)
            return cpu

        def get_mem(self, find_types, package_name):
            try:
                mem_result = os.popen(("adb shell dumpsys meminfo  | %s  %s") % (find_types, package_name))
                mem_list = mem_result.readline().split()
                # print(mem_list)
                if len(mem_list) > 0:
                    mem = mem_list[0].replace("K:", "")
                else:
                    mem = "0"
                # print(mem)
            except e:
                print("error:"+e)
            return mem

        def get_bytes_uid(self,find_types, package_name):
            uid_str = os.popen(("adb shell ps | %s %s") % (find_types, package_name))
            uid_list = uid_str.readline().split()
            print("uid :" + uid_list[1])
            return uid_list[1]

        def get_bytes(self, find_types):
            bytes_list = []
            bytes_result = os.popen(("adb shell cat /proc/%s/net/dev | %s wlan0") % (GetRes.get_bytes_uid(), find_types))
            bytes_value = bytes_result.readline()
            recv = int(bytes_value.split()[1])
            send = int(bytes_value.split()[9])
            bytes_list.append(recv)
            bytes_list.append(send)
            print(recv / 1024)
            print(send / 1024)
            return recv, send, bytes_list, recv - send


if __name__ == '__main__':
    getRes = GetRes()
    getRes.phone_info()





